package com.kepler.social.domain.support.media.mq;

import com.kepler.social.domain.support.media.vo.CallBackVo;
import com.kepler.social.domain.support.media.vo.FileSliceVo;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import lombok.RequiredArgsConstructor;

import java.util.List;


@RequiredArgsConstructor
public class SliceMergeProducer {

    private final Disruptor disruptor;

    /**
     * 发送数据
     *
     * @param fileSlices
     * @param callBack
     */
    public void send(List<FileSliceVo> fileSlices, CallBackVo callBack) {
        RingBuffer<SliceMergeMessage> ringBuffer = disruptor.getRingBuffer();
        // 获取可以生成的位置
        long next = ringBuffer.next();
        try {
            SliceMergeMessage msg = ringBuffer.get(next);
            msg.setFileSlices(fileSlices);
            msg.setCallBack(callBack);
        } finally {
            ringBuffer.publish(next);
        }
    }

}